package com.zmj.sy.mom.srv.aps.service.scheduler.resource.shift;

import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;

public class TimeUtils {

    public static Duration time(String timeValue, Integer timeUnit) {
        if (StringUtils.hasText(timeValue)) {
            if (timeUnit.equals(1)) {
                return Duration.ofSeconds(
                        new BigDecimal(timeValue)
                                .multiply(new BigDecimal(60 * 60 * 24))
                                .setScale(0, RoundingMode.UP)
                                .intValue()
                );
            } else if (timeUnit.equals(2)) {
                return Duration.ofSeconds(
                        new BigDecimal(timeValue)
                                .multiply(new BigDecimal(60 * 60))
                                .setScale(0, RoundingMode.UP)
                                .intValue()
                );
            } else if (timeUnit.equals(3)) {
                return Duration.ofSeconds(
                        new BigDecimal(timeValue)
                                .multiply(new BigDecimal(60))
                                .setScale(0, RoundingMode.UP)
                                .intValue()
                );
            } else if (timeUnit.equals(4)) {
                return Duration.ofSeconds(
                        new BigDecimal(timeValue)
                                .setScale(0, RoundingMode.UP)
                                .intValue()
                );
            }
        }
        return Duration.ZERO;
    }

}
